<?php

namespace app\api\controller\logistics;

use app\common\controller\qyg\Api;

class Common extends Api
{

    protected $noNeedLogin = "*";
    protected $noNeedRight = "*";


    /**
     * 获取省市区
     */
    public function area()
    {
        $tree = [];
        $packData = [];
        // 把数组的引用赋给新数组
        foreach (collection(model('app\common\model\Area')->field('id,pid,name,level')->select())->toArray() as $vo) {
            $packData[$vo['id']] = $vo;
        }
        // 获取树状结构的数组
        foreach ($packData as $key => $val) {
            if ($val['pid'] == 0)
                $tree[] = &$packData[$key];
            else
                if($val['level'] === 3){
                    $packData[$val['pid']]['area'][] = &$packData[$key];
                }else{
                    $packData[$val['pid']]['city'][] = &$packData[$key];
                }
        }
        $this->success('返回成功', $tree);
    }

    public function get_cfg()
    {
        $cfg = config("site");
        $this->success("ok",["map_key"=>$cfg["map_key"],"app_id"=>$cfg["app_id"]]);
    }
}